package cn.wolfcode.wolf2w.business.service.impl;

import cn.wolfcode.wolf2w.business.api.RemoteNoteService;
import cn.wolfcode.wolf2w.business.api.domain.Note;
import cn.wolfcode.wolf2w.business.api.domain.NoteEs;
import cn.wolfcode.wolf2w.business.repository.NoteEsRepository;
import cn.wolfcode.wolf2w.business.service.INoteEsService;
import cn.wolfcode.wolf2w.common.core.constant.SecurityConstants;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class NoteEsServiceImpl implements INoteEsService {
    @Autowired
    private RemoteNoteService remoteNoteService;

    @Autowired
    private NoteEsRepository noteEsRepository;

    @Override
    public void initNoteEs() {
        //返回所有攻略的数组
        List<Note> list= remoteNoteService.list(SecurityConstants.INNER).getData();
        List<NoteEs> esList = new ArrayList<>();

        for (Note note : list) {
            NoteEs es = new NoteEs();
            //同名属性用拷贝,第一个参数：源头，第二个：目的
            BeanUtils.copyProperties(note,es);
            esList.add(es);
        }
        noteEsRepository.saveAll(esList);
    }
}